package top.jiangqiang.qianyi.common.validate;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.dromara.hutool.core.array.ArrayUtil;

public class NotAllowValidator implements ConstraintValidator<NotAllow, Object> {
    private String[] notAllowValues;

    @Override
    public void initialize(NotAllow constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
        notAllowValues = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return !ArrayUtil.contains(notAllowValues, String.valueOf(value));
    }
}
